<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript">
        function validate_name(field){
            with (field){
                alert("数据不能为空")
return false;
            }
        }

        function validate_password(field){
            with (field){
                if (value!=null){
                    return true;
                }
                alert("密码不能为空")
                return false;
            }
        }


        function valid(thisform){
            with (thisform){
                if(validate_name(username)==false){
                return false;
                }
                if(validate_password(password)==false){
                    return false;
                }
            }
        }

    </script>
</head>

<body>
<form action="DOMdemo.html" onsubmit="return valid(this)">
    <input type="text" name="username">
    <input type="password" name="password">
    <input type="email" name="youemail">
    <input type="submit" value="submit">
</form>
</body>

</html>